package myJs.api

import japgolly.scalajs.react.extra.Ajax
import myJs.myPkg.MyFetch
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import upickle.default._

/** Created by yz on 12/9/2023
  */
object Gene {

  val baseUrl = s"${Api.apiUrl}/gene"

  def allBySymbol(symbol: String) = {
    val url = s"${baseUrl}/allBySymbol?symbol=${symbol}"
    Ajax("GET", s"${url}").setRequestContentTypeJson.send.asAsyncCallback
      .map { xhr =>
        read[List[ujson.Obj]](xhr.responseText)
      }
  }

  def all = {
    val url = s"${baseUrl}/all"
    Ajax("GET", s"${url}").setRequestContentTypeJson
                          .send
                          .asAsyncCallback
                          .map { xhr =>
                            read[List[ujson.Obj]](xhr.responseText)
                          }
  }


}
